# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=retdec
pkgbase=mingw-w64-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
pkgver=r781.c31c316
pkgrel=1
pkgdesc="Retargetable machine-code decompiler based on LLVM (mingw-w64)"
arch=('any')
url="https://retdec.com/"
license=('MIT')
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
depends=("${MINGW_PACKAGE_PREFIX}-clang"
         "${MINGW_PACKAGE_PREFIX}-doxygen"
         "${MINGW_PACKAGE_PREFIX}-gcc"
         "${MINGW_PACKAGE_PREFIX}-python3")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "git")
options=('strip')
source=("${_realname}"::"git+https://github.com/avast-tl/retdec.git")
sha256sums=('SKIP')

pkgver() {
  cd "${srcdir}/${_realname}"
  printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd ${_realname}
}

build() {
  [[ -d "build-${MINGW_CHOST}" ]] && rm -rf "build-${MINGW_CHOST}"
  mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    ../${_realname}

  make
}

package() {
  cd build-${MINGW_CHOST}
  make DESTDIR=${pkgdir} install
  install -Dm644 ${srcdir}/${_realname}/LICENSE ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
  install -Dm644 ${srcdir}/${_realname}/LICENSE-THIRD-PARTY ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE-THIRD-PARTY
}
